// Copyright (C) 2011 YANG Hao (yangh2007@gmail.com). All rights reserved.
//
// This file is part of the (cute)octopus project.
//
// This file may be distributed and/or modified under the terms of the
// GNU General Public License version 2 as published by the Free Software
// Foundation.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Author(s): YANG Hao

#ifndef OAPPLICATION_H
#define OAPPLICATION_H

#include <QApplication>
#include <QMainWindow>
#include "ostd.h"

class OAction;
class OEvent;
class OCreator;
class ODoc;
class OTask;
class OWindow;

class OCTOPUS_EXPORT OApplication : public QApplication
{
public:
	OApplication(int & argc, char ** argv);
	~OApplication();

	// main interfaces

	// Execute application with the given OCreator
	int exec(OCreator* c);
	
	// Returns the current focused mdi window of this application
	OWindow* currentWindow() const;

	// Returns the document displayed by currentWindow()
	ODoc* currentDocument() const;

	// Returns the current active action
	OAction* currentActiveAction() const;

	// Returns the document bound by the given file path
	ODoc* document(const QString& filePath) const;

	// Returns all Widgets attached to this doc 
	QList<QWidget*> widgets(ODoc* doc) const;

	// Returns all open documents
	QList<ODoc*> allDocuments() const;

	// Returns all open widgets
	QList<QWidget*> allWidgets() const;

	// open the doc
	ODoc* openDocument(const QString& filePath);

	// create widget
	QWidget* createWidget(ODoc* doc);
	
	// message posters
	void notify(OEvent* message) const;	
};

// Get the OApplication running instance
inline OApplication* oApp()	{return static_cast<OApplication*>(qApp);}


#endif // OAPPLICATION_H
